package com.mingliqiye.minecraft.enchantment.conflict.forge.mixin;

import com.mingliqiye.minecraft.enchantment.conflict.forge.ForgeMod;
import net.minecraft.core.Holder;
import net.minecraft.world.item.enchantment.Enchantment;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Enchantment.class)
public class EnchantmentMixin {

    @Inject(method = "areCompatible", at = @At("HEAD"), cancellable = true)
    private static void onAreCompatible(
            Holder<Enchantment> holder, Holder<Enchantment> holder2, CallbackInfoReturnable<Boolean> cir
    ) {
        var a = holder.unwrapKey().get().location().toString();
        var b = holder2.unwrapKey().get().location().toString();
        var c = ForgeMod.ENCHANTMENTCONTROLLER.canBeCombined(a, b);
        if (c != null) {
            cir.setReturnValue(c);
        }
    }
}
